Skip to content

Let All threads load threads older than the newest 100 - #440

Merged
abhishekgahlot2 merged 5 commits into
useagenthq:mainfrom
officialasishkumar:feature/page-all-threads
Nov 12, 2026
Merged

abhishekgahlot2 merged 5 commits into
useagenthq:mainfrom
officialasishkumar:feature/page-all-threads

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.

Fixes #219
Fixes #297

All threads reads one bounded snapshot: the 100 most recently active thread roots plus any older queued or running ones. A thread outside that snapshot could only be opened by typing its URL. The two issues ask for the same thing from the API side (#219) and the page side (#297), so this does both.

What changed

GET /api/runs?view=summary pages (backend/src/runs/run-summaries.ts, backend/src/runs/read-routes.ts)

  • The response now carries has_more and next_cursor. Send next_cursor back as cursor, with the same all, limit and include_active, to get the rows that sort after the page. runs is unchanged, so current callers see the same first page.
  • The cursor is the last row's full sort key: latest turn updated_at, latest turn created_at, latest turn id, root created_at, root id (or created_at and id with all=1). "After the cursor" is one row-value comparison, so a page cut between rows that share a timestamp keeps the id order.
  • Timestamps go into the cursor as Postgres text with microseconds, cast back with ::timestamptz, the way the execution graph cursor does it. A JavaScript Date rounds to milliseconds, which repeats or skips rows that fall inside one millisecond.
  • The list is ordered by each thread's latest turn, so a thread that gets a new turn while someone pages moves to the front of the newest page. It does not shift the later pages.
  • With include_active=1, the first page still carries up to limit active rows that sort after it, as before. Later pages leave out exactly those rows, so no thread is listed twice.
  • A malformed cursor, or a cursor from the other view (roots-only and all=1 sort by different keys), answers 400 {"error":"cursor is invalid"}. The query is still scoped to the caller's org, so a cursor carries nothing across workspaces.
  • listRunSummaries moves out of runs/repo.ts, which was at the 800-line cap, into runs/run-summaries.ts next to the cursor helpers. The SQL that builds each row is the same as before.

All threads page (frontend/app/(workspace)/agent/runs/)

  • A "Show older threads" button under the table loads the page after the current cursor and adds it to the list. It shows only while the backend reports more.
  • The newest page stays live (change stream plus the 15s recovery poll). The older pages stay loaded across those refreshes. If a thread from an older page reappears in a refreshed newest page, it is listed once, from the newest page (mergeRunPages).
  • A failed page shows "Couldn't load older threads." (role="alert") and a Try again button that resends the same cursor. Rows already shown stay.
  • The search box now reads "Search loaded threads", next to the existing "Loaded results" count, so it is clear the search covers only the threads loaded so far.

Docs: the /api/runs row and a short paging note in docs-site/docs/api/runs.mdx.

Across a release: an old web client ignores the new fields. A new client talking to an old backend gets no next_cursor, so the button stays hidden.

Tests

backend/test/run-summary-pages.test.ts runs through the real route and database. It seeds 150 threads where indices 45 to 54 share one timestamp exactly and 98 to 105 sit one microsecond apart, so the page cuts land inside both groups:

  • limit=50 gives pages of 50, 50 and 50, and together they match the one-shot limit=1000 order exactly
  • limit=7 (22 pages) matches the one-shot order too, cutting inside the tie groups at many points
  • include_active=1 gives pages of 54 (50 plus the 4 older active threads), 50 and 46: 150 distinct threads, and no active thread on a later page
  • a thread updated after page 1 is on neither later page, and the next newest page leads with it
  • all=1 covers all 153 runs (replies included) in the one-shot order
  • malformed, empty, wrong-shape, wrong-view and bad-timestamp cursors each answer 400
  • a cursor from another workspace lists only the caller's own threads

As a check on the microsecond handling, I switched the cursor timestamps to millisecond precision and four of these tests failed.

Frontend:

  • runs-list.interaction.test.tsx mounts RunsList under happy-dom, using the real runs-data helpers over a stubbed fetch. It covers:
    • two older pages appended, with a duplicate dropped and the button gone at the end
    • a run change on the stream re-reading only the newest page while the older rows stay
    • a 503 showing the alert, then Try again resending the same cursor
  • runs-data.test.ts: the request paths, cursor encoding, a missing or malformed next_cursor read as the last page, and mergeRunPages
  • runs-list.test.ts: the button renders only with a cursor

Checks with Bun 1.3.14, backend tests on pgvector/pgvector:0.8.6-pg16-bookworm:

  • bun run typecheck (root): passes
  • cd backend && bun test test/run-summary-pages.test.ts test/runs.test.ts test/native-children-sidebar.test.ts test/slack-turn-identity.test.ts test/cancel.test.ts test/ratchet.test.ts test/persisted-names.test.ts: all pass
  • cd frontend && bun run test: 1939 pass, 0 fail
  • cd frontend && bunx biome lint "app/(workspace)/agent/runs": no new findings (the 5 warnings are the existing ones in runs-data.test.ts)
  • bun test scripts/agent-docs.test.ts: 5 pass

I did not run the full backend suite or bun run build, and I did not try the page in a browser, so I have no screenshots.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

All threads, like the sidebar, read one bounded snapshot: the 100 most
recently active thread roots plus any older queued or running ones. A
thread outside that snapshot could only be opened by typing its URL.

GET /api/runs?view=summary now pages. Each response carries has_more and
next_cursor; sending next_cursor back as cursor, with the same all, limit
and include_active, returns the rows that sort after the page.

- The cursor is the last row's full sort key (latest turn update time,
  latest turn creation time, latest turn id, root creation time, root id;
  or creation time and id with all=1), so a page boundary inside rows that
  share a timestamp keeps the id order. Timestamps keep Postgres' text
  form with microseconds, as the execution graph cursor does: a
  JavaScript Date would round them to milliseconds and repeat or skip
  rows.
- Because the list is ordered by each thread's latest turn, a thread that
  gets a new turn while someone pages moves to the front instead of
  shifting every later page.
- With include_active, the first page still carries up to limit active
  rows that sort after it, and later pages leave exactly those rows out,
  so no thread is listed twice.
- A malformed cursor, or one from the other view, answers
  400 {"error":"cursor is invalid"}.

listRunSummaries moves from runs/repo.ts, which sat at the 800-line cap,
into runs/run-summaries.ts with the cursor helpers.

The All threads page keeps the newest page live (stream and recovery
poll) and adds a "Show older threads" button under the table that appends
the next page. Rows from older pages that reappear in a refreshed newest
page are shown once, from the newest page. A failed page says so and
offers Try again with the same cursor. The search box now says it
searches loaded threads.

The API reference documents the cursor.

Closes useagenthq#219
Closes useagenthq#297

@abhishekgahlot2 abhishekgahlot2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @officialasishkumar, the backend cursor is solid: the full sort key ending in the root id, timestamps round-tripped with microseconds, one row-value comparison that matches the ORDER BY, and org-scoped throughout.

One thing to fix before merging: threads can drop out of the list once "Show older threads" has been used.

  • Each refresh replaces the newest page with the current top 100 (runs-list.tsx:265), while the older pages keep the cursor taken from the original newest page (runs-list.tsx:296, :308), and mergeRunPages (runs-data.ts:69) only de-duplicates.
  • When a new thread arrives (or an older one gets a new turn), the row that was 100th slides to 101st. It is no longer in the refreshed newest page, and the older pages start strictly after it, so it is in neither list until a reload. Search over loaded threads misses it too.
  • Repro in the PR's own interaction test setup: newest [a,b], older [c]; a new thread arrives and newest refreshes to [n,a]. Thread b disappears and the list shows "3 of 3 runs".

A possible fix: while older pages are loaded, merge the previous newest rows back in (setNewest(prev => older ? mergeRunPages(page.runs, prev) : page.runs)), or re-read the newest page with a limit that covers every loaded row. A test for the new-thread-arrives case would lock it in.

Smaller, non-blocking: a cursor timestamp like 2026-02-30 ... passes Date.parse but Postgres rejects it, so it answers 500 instead of 400.

… loaded

Refreshing the newest page replaced it with the current top 100 while the
older pages kept the cursor from the original page, so a row pushed past
the limit by a new thread was in neither list. Merge the previous newest
rows back in while older pages are loaded.

Also reject a cursor timestamp with an impossible date or time as an
invalid cursor (400) instead of letting Postgres fail it with a 500.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

Fixed in 4ea8d23: while older pages are loaded, a newest-page refresh now merges the previous rows back in, with a test for the new-thread case. Also made a cursor with an impossible date like 2026-02-30 answer 400.

@abhishekgahlot2 abhishekgahlot2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, the refresh-after-load case now holds and the new test covers it.

One window is still open: olderLoaded.current = true is set after await fetchRuns({ cursor }) returns (runs-list.tsx:310). A newest-page refresh that lands while the older request is in flight still takes the replace branch (:269), and the older page then starts after the old cursor, so the row at the boundary is in neither list.

Repro in the PR's interaction test setup: click "Show older threads", hold that request, refresh newest to [n,a], then release. The list shows "3 of 3 runs" and b is missing.

Fix: set olderLoaded.current = true before the fetch, right after setOlderFailed(false). With that the same probe shows "4 of 4 runs" and all 19 runs tests pass. A test for the in-flight case would lock it in.

A newest-page refresh that landed while the older request was in flight
replaced the newest rows, so the row at the cursor boundary was in
neither list.
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

Fixed in 5124b4f: olderLoaded is now set before the older request starts, with a test that holds the request while the newest page refreshes.

@abhishekgahlot2
abhishekgahlot2 merged commit 493ed0a into useagenthq:main Nov 12, 2026
40 of 41 checks passed
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

Merged, thanks @officialasishkumar. Marking older pages loaded before the request closes the in-flight window too, so no thread drops out at the page boundary any more.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let All threads show threads older than the newest 100 Let the Runs page list threads past the newest 100

2 participants